package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
public interface OrderMapper extends BaseMapper<Order> {
    @Select("select count(1) from t_order where setmeal_id=#{sid} and orderdate=#{orderDate} and member_id=#{mid}")
    int findOrderBySetMealIdAndOrderDateAndMemberId(@Param("sid") int sid, @Param("orderDate") String orderDate, @Param("mid") int mid);

    @Select("SELECT tm.name as member , ts.name as setmeal ,tor.ORDERDATE as orderDate , tor.ORDERTYPE as orderType " +
            "FROM  t_member tm, t_setmeal ts ,t_order tor " +
            "WHERE  tm.id = tor.MEMBER_ID and ts.id = tor.SETMEAL_ID " +
            "and tor.id = #{id}")
    Map findOrderInfoByOrderId(@Param("id") Integer id);

    @Select("SELECT s.name,count(s.id) count,count(s.id)/(select count(1) from t_order) rate\n" +
            "FROM t_order r,t_setmeal s\n" +
            "where s.id=r.SETMEAL_ID\n" +
            "group by s.id\n" +
            "ORDER BY count(s.id) desc")
    List<Map> getHotSetmeal();
}
